Skip to content

fix(fsharp): propagate DerivedVariable IsReferenced to same-named Arguments - #563

Merged
jeremydmiller merged 2 commits into
JasperFx:mainfrom
thechucklingatom:main
Jul 26, 2026
Merged

fix(fsharp): propagate DerivedVariable IsReferenced to same-named Arguments#563
jeremydmiller merged 2 commits into
JasperFx:mainfrom
thechucklingatom:main

Conversation

@thechucklingatom

Copy link
Copy Markdown
Contributor

WriteFSharpMethod prefixes unreferenced method arguments with _ to
satisfy
the F# compiler's unused-variable warnings. The check used
arg.IsReferenced,
but a method argument and a DerivedVariable that aliases the same name
are
distinct Variable instances — so marking one referenced had no effect on
the
other.

Concrete case: Wolverine's HandlerChain adds ContextVariable("context",
IMessageContext) to DerivedVariables so middleware can resolve
IMessageContext.
When a middleware frame resolves that alias and marks it referenced, the
actual
HandleAsync argument (context: MessageContext) stayed IsReferenced =
false.
WriteFSharpMethod then emitted _context in the signature while the
generated
body still used context, producing FS0039 ("value or constructor
'context' is
not defined") on every handler that had IMessageContext-consuming
middleware.

Fix: before building the argument list in WriteFSharpMethod, walk
Arguments and
set IsReferenced = true on any whose Usage matches a referenced
DerivedVariable.
Setting it on the Variable object itself (inside the JasperFx assembly,
so
internal set is reachable) keeps all downstream codegen — including
frames
that read arg.IsReferenced directly — consistent with the updated state.

…uments

WriteFSharpMethod prefixes unreferenced method arguments with `_` to
satisfy
the F# compiler's unused-variable warnings. The check used
arg.IsReferenced,
but a method argument and a DerivedVariable that aliases the same name
are
distinct Variable instances — so marking one referenced had no effect on
the
other.

Concrete case: Wolverine's HandlerChain adds ContextVariable("context",
IMessageContext) to DerivedVariables so middleware can resolve
IMessageContext.
When a middleware frame resolves that alias and marks it referenced, the
actual
HandleAsync argument (`context: MessageContext`) stayed IsReferenced =
false.
WriteFSharpMethod then emitted `_context` in the signature while the
generated
body still used `context`, producing FS0039 ("value or constructor
'context' is
not defined") on every handler that had IMessageContext-consuming
middleware.

Fix: before building the argument list in WriteFSharpMethod, walk
Arguments and
set IsReferenced = true on any whose Usage matches a referenced
DerivedVariable.
Setting it on the Variable object itself (inside the JasperFx assembly,
so
`internal set` is reachable) keeps all downstream codegen — including
frames
that read arg.IsReferenced directly — consistent with the updated state.
@jeremydmiller
jeremydmiller merged commit 58bdfc9 into JasperFx:main Jul 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants